﻿//#include <iostream>
//
//using namespace std;
////sn = (a1 + an) / 2 * n
//typedef long long LL;
//int main()
//{
//	LL q; cin >> q;
//	while (q--)
//	{
//		LL a, b; cin >> a >> b;
//		LL cnt = (b - a + 1) % 9;
//		LL ans = cnt *(a % 9) % 9 + (cnt) * (cnt - 1) % 9 * 5 % 9;
//		cout << ans % 9 << endl;
//	}
//	return 0;
//}

#include <iostream>
#include <set>

using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
set<int> s[3];
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		s[x].insert(i);
	}

	while (s[0].size() || s[1].size())
	{
		// 1. 先确定最⼩值所在的集合
		int p;
		// 必定在 s[0] ⾥⾯挑
		if (s[1].empty() || (s[0].size() && *s[0].begin() < *s[1].begin())) p = 0;
		else p = 1;
		// 2. 循环交替拿元素
		int x = 0;
		while (1)
		{
			auto it = s[p].upper_bound(x);
			if (it == s[p].end()) break;
			cout << *it << " ";
			x = *it;
			s[p].erase(it);
			// p = 0 -> p = 1 p = 1 -> p = 0
			p = !p;
		}
		cout << endl;
	}
	return 0;
}